package com.brspace.qualitycontrol.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.brspace.qualitycontrol.entity.UserRoleRelation;
import com.brspace.qualitycontrol.entity.vo.UserRoleVo;
import com.brspace.qualitycontrol.mapper.UserRoleRelationMapper;
import com.brspace.qualitycontrol.service.UserRoleRelationService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wangt
 * @since 2021-03-23
 */
@Service
public class UserRoleRelationServiceImpl extends ServiceImpl<UserRoleRelationMapper, UserRoleRelation> implements UserRoleRelationService {
    @Resource
    private UserRoleRelationMapper userRoleRelationMapper;
    /**
     * 给用户分配角色
     * @Author: wangt
     * @Date: 2021-04-20 16:42:51
     */
    @Override
    public void add(UserRoleVo userRoleVo) {
        for (String user : userRoleVo.getUserId()) {
            baseMapper.deleteById(user);
        }
        for (String s : userRoleVo.getUserId()) {
            for (Integer integer : userRoleVo.getRoleId()) {
                UserRoleRelation roleVo = new UserRoleRelation();
                roleVo.setUserId(s);
                roleVo.setRoleId(integer);
                userRoleRelationMapper.insert(roleVo);
            }
        }
    }
}
